package com.example.microservice.common.exception.pojo;

import org.springframework.http.HttpStatus;

/**
 * @Author: caohuijie
 * @Date: 创建日期 2018/11/20
 * @Modified By:
 * @Description: 错误信息response
 */
public class ApiErrorResponse {

    /**
     * HTTP状态代码
     */
    private Integer status;

    /**
     * REST API特定的错误代码。此字段有助于传递API
     * /业务领域中特定信息。比如类似Oracle错误ORA-12345
     */
    private String error_code;

    /**
     * 人类可读的错误消息。国际化信息
     */
    private String message;

    /**
     * 完整详细信息。
     */
    private String detail;

    /**
     * 有关错误或异常的详细信息的链接
     */
    private String information_link;


    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getError_code() {
        return error_code;
    }

    public void setError_code(String error_code) {
        this.error_code = error_code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getDetail() {
        return detail;
    }

    public void setDetail(String detail) {
        this.detail = detail;
    }

    public String getInformation_link() {
        return information_link;
    }

    public void setInformation_link(String information_link) {
        this.information_link = information_link;
    }

    public static final class ApiErrorResponseBuilder {
        private Integer status;
        private String error_code;
        private String message;
        private String detail;

        public ApiErrorResponseBuilder() {
        }

        public static ApiErrorResponseBuilder anApiErrorResponse() {
            return new ApiErrorResponseBuilder();
        }

        public ApiErrorResponseBuilder withStatus(HttpStatus status) {
            this.status = status.value();
            return this;
        }

        public ApiErrorResponseBuilder withError_code(String error_code) {
            this.error_code = error_code;
            return this;
        }

        public ApiErrorResponseBuilder withMessage(String message) {
            this.message = message;
            return this;
        }

        public ApiErrorResponseBuilder withDetail(String detail) {
            this.detail = detail;
            return this;
        }

        public ApiErrorResponse build() {
            ApiErrorResponse apiErrorResponse = new ApiErrorResponse();
            apiErrorResponse.status = this.status;
            apiErrorResponse.error_code = this.error_code;
            apiErrorResponse.detail = this.detail;
            apiErrorResponse.message = this.message;
            return apiErrorResponse;
        }
    }
}
